Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): return 404 if get backing image and backup not found #2067

Conversation

ChanYiLin
Copy link
Contributor

shuo-wu
shuo-wu previously approved these changes Jul 10, 2023
Copy link
Contributor

@shuo-wu shuo-wu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to handle volume/backupvolume for CSI API DeleteSnapshot?
The idea LGTM.

api/backingimage.go Outdated Show resolved Hide resolved
api/backup.go Outdated Show resolved Hide resolved
@ChanYiLin ChanYiLin force-pushed the LH6266_server_should_return_404_for_backing_and_backup_resource branch from d80e226 to 872307f Compare July 11, 2023 04:01
@ChanYiLin
Copy link
Contributor Author

ChanYiLin commented Jul 11, 2023

VolumeSnapshot has 3 types

  • backing image
  • snapshot
  • backup

When deleting

  • csi: try to get the CR first, it it doesn't exist, then pass
  • client: check if 404, return CR=nil
  • server: return 404, if it cannot get the CR from datastore

@ChanYiLin ChanYiLin requested a review from innobead July 11, 2023 04:06
@ChanYiLin ChanYiLin force-pushed the LH6266_server_should_return_404_for_backing_and_backup_resource branch from 872307f to 9f28b19 Compare July 11, 2023 05:34
@ChanYiLin ChanYiLin changed the title fix(server): return 404 if get backing image and backup not found [WIP: e2e test]fix(server): return 404 if get backing image and backup not found Jul 11, 2023
innobead
innobead previously approved these changes Jul 11, 2023
Copy link
Member

@innobead innobead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@innobead
Copy link
Member

@shuo-wu Please help review this.

@innobead innobead requested a review from shuo-wu July 11, 2023 05:39
@ChanYiLin
Copy link
Contributor Author

@innobead
I am running the e2e test, and it failed at backup snapshot
Let me check for it

@innobead
Copy link
Member

NP. Passing the test is the criteria before merging.

@ChanYiLin
Copy link
Contributor Author

weird, it passed the test in my environment
need some time to investigate

ref: longhorn/longhorn 6266

Signed-off-by: Jack Lin <jack.lin@suse.com>
@ChanYiLin ChanYiLin force-pushed the LH6266_server_should_return_404_for_backing_and_backup_resource branch from f159724 to a333f30 Compare July 11, 2023 10:57
@ChanYiLin
Copy link
Contributor Author

ChanYiLin commented Jul 11, 2023

I know the reason why
Because I used /v1/backups/XXX in our generated client (link) to try to get the backup before deleting it
Turns out, we don't provide such API in our server
So csi thought there was no such backup and pass the deletion, and failed when checking if the backup still existed in the python test.

@ChanYiLin
Copy link
Contributor Author

ChanYiLin commented Jul 11, 2023

We don't have to check by getting the backup or snapshot before deletion
because in the delete api we already pass the deletion if it is not found

backup, err := s.m.GetBackup(input.Name, volName)
if err != nil {
logrus.WithError(err).Warnf("failed to get backup '%v' of volume '%v'", input.Name, volName)
}
if backup != nil {
if err := s.m.DeleteBackup(input.Name, volName); err != nil {
return errors.Wrapf(err, "failed to delete backup '%v' of volume '%v'", input.Name, volName)
}
}

so removed the check

@ChanYiLin
Copy link
Contributor Author

@shuo-wu
Copy link
Contributor

shuo-wu commented Jul 11, 2023

We don't have to check by getting the backup or snapshot before deletion
because in the delete api we already pass the deletion if it is not found
longhorn-manager/api/backup.go
so removed the check

Sorry... Does the PR contain the removal (of getting backing image/backup volume before requesting deletion)...? BTW, for the snapshot deletion, getting volume is unavoidable. We still need to make sure getting a nil volume should be handled as expected.

@ChanYiLin
Copy link
Contributor Author

ChanYiLin commented Jul 11, 2023

Hi @shuo-wu
No, this PR maintains the same as before, I didn't remove anything in csi part
And only add 404 not found header in server side
I am saying, for csi part, I have removed all the changes I made earlier since the deletion api for backup and snapshot already check if it exists

@ChanYiLin ChanYiLin changed the title [WIP: e2e test]fix(server): return 404 if get backing image and backup not found fix(server): return 404 if get backing image and backup not found Jul 11, 2023
@ChanYiLin
Copy link
Contributor Author

@shuo-wu
Copy link
Contributor

shuo-wu commented Jul 11, 2023

OK. I was thinking you directly remove the backup volume/backing image get calls from the CSI SnapshotDelete implementation. But this is an alternative solution for this issue while making the implementation simpler. WDTY?

@ChanYiLin
Copy link
Contributor Author

ChanYiLin commented Jul 11, 2023

I think if from server side it already checks if it exists before deleting it
We don't need to do it in client side again
and if we do it in client side, we have to make sure every client call has checked if it exists?
I would say it adds the burden to the client side.

@ChanYiLin
Copy link
Contributor Author

ChanYiLin commented Jul 11, 2023

In conclusion
For this issue, it only effect BackingImage, because it gets the BackingImage and then delete it
But the get api return 500 if it is not found instead of 404, the deletion process failed
In this PR, I add the 404 if get function has not found error then the clenup for BackingImage could pass.

For backup and snapshot, they have parent resources which are backupVolume and volume
CSI gets the parent resource first and then delete the backup and snapshot
The process would be

  • if volume or backupVolume doesn't exists -> get 404 not found error then bypass the deletion (already did before)
  • call api delete snapshot -> delete api already check if snapshot or backup exists, no need to check in client side again

@innobead
Copy link
Member

So do we need to do any other code change here?

@ChanYiLin
Copy link
Contributor Author

So do we need to do any other code change here?

No, I have tested it manually and through e2e
Three types of volumesnapshot can be successfully deleted in any case

@shuo-wu
Copy link
Contributor

shuo-wu commented Jul 12, 2023

I mean, for backing image cleanup, since there is no parent resource, there is no need to invoke cs.apiClient.BackingImage.ById(backingImageParameters[longhorn.BackingImageParameterName]) before deletion. We can directly call cs.apiClient.BackingImage.Delete(backingImage)

@ChanYiLin
Copy link
Contributor Author

@shuo-wu
But in csi we don't have longhorn CR clientset only have longhorn api client
so we manipulate the resources through api client
and for BackingImage delete api, it needs BackingImage object

Even we delete the BackingImage directly, if it doesn't exist, we still need to handle not found error
I don't think the process will be different

  • get -> if found -> delete
  • delete -> if not found error then pass

And besides this issue, we still need to add 404 not found in the server api for other cases, maybe there are some places in our code also use 404 to determine if api has not found error.

@innobead innobead merged commit a523288 into longhorn:master Jul 12, 2023
3 checks passed
@innobead
Copy link
Member

@mergify backport v1.5.x

@mergify
Copy link

mergify bot commented Jul 12, 2023

backport v1.5.x

✅ Backports have been created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants